package org.nobody.mallb2c.mallsearch.controller;

import org.nobody.mallb2c.mallsearch.service.MallSearchService;
import org.nobody.mallb2c.mallsearch.vo.SearchParam;
import org.nobody.mallb2c.mallsearch.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 3489309323@qq.com
 * @create 2020-09-11-16:40
 */
@Controller
public class SearchController {
  @Autowired
  MallSearchService mallSearchService;

  @GetMapping("/list.html")
  public String listPage(SearchParam/*←会自动将页面提交过来的所有请求查询参数封装成指定的对象*/ param, Model model, HttpServletRequest request){
    //1、 根据传递来的页面的查询参数,去es中检索商品

    param.set_queryString(request.getQueryString());
    SearchResult result = mallSearchService.search(param);

    model.addAttribute("result", result);

    System.out.println("result: " + result);
    return "list";
  }
}
